home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: ZStringData.cpp
-
- Contains: Data backing object for ZStrings.
-
- Written by: Eric Traut
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- #include "ZStringData.h"
-
- #include <string.h>
- #include <stddef.h>
- #include <new>
-
-
- /*------------------------------------------------------------------
- Allocate [static]
- ------------------------------------------------------------------*/
-
- ZStringData *
- ZStringData::Allocate(
- Z_UInt32 inStringLength)
- {
- Z_UInt32 sizeNeeded = offsetof(ZStringData, mStringData) + inStringLength + 1;
- ZStringData * newData = reinterpret_cast<ZStringData *>(new (std::nothrow) Z_UInt8[sizeNeeded]);
-
- if (newData != NULL)
- {
- newData->mRefCount = 0;
- newData->mStringLength = inStringLength;
- newData->mStringData[inStringLength] = '\0';
- }
-
- return newData;
- }
-
-
- /*------------------------------------------------------------------
- Deallocate
- ------------------------------------------------------------------*/
-
- void
- ZStringData::Deallocate()
- {
- delete [] (Z_UInt8 *)this;
- }
-
-
- /*------------------------------------------------------------------
- FillInString
- ------------------------------------------------------------------*/
-
- void
- ZStringData::FillInString(
- const char * inString,
- Z_UInt16 inOffset,
- Z_UInt16 inLength)
- {
- check(inOffset + inLength <= mStringLength);
- memcpy(mStringData + inOffset, inString, inLength);
- }
-
-
-